window.addEventListener('load', () => {
    var finalUrl = sessionStorage.getItem('finalUrl');
    // console.log(finalUrl);
    axios.get(finalUrl)
        .then(Response => {
            // console.log(Response.data.data);
            addPassageInformation(Response);
        })
        .catch(err => {
            console.log(err);
        })


    var passageTitle = document.querySelector('.passageTitle');
    var userInfoName = document.querySelectorAll('.userInfoName');
    var createTime = document.querySelector('.createTime');
    var userInfoAvatar = document.querySelectorAll('.userInfoAvatar');
    var userInfoAvatarImg0 = userInfoAvatar[0].querySelector('img');
    var userInfoAvatarImg1 = userInfoAvatar[1].querySelector('img');
    var passageContent = document.querySelector('.passageContent');
    var passageImg = document.querySelector('.passageImg');
    var coverUrl = passageImg.querySelector('img');
    var userInfoJob = document.querySelector('.userInfoJob');
    var userInfoCompany = document.querySelector('.userInfoCompany');
    var passageLikeCount = document.querySelector('.passageLikeCount');
    var likeCount = passageLikeCount.querySelector('p');
    var passageCommentCount = document.querySelector('.passageCommentCount');
    var commentCount = passageCommentCount.querySelector('p');

    // 获取数据并将返回的数据填充到网页里面
    function addPassageInformation(Response) {
        passageTitle.innerHTML = Response.data.data.title;
        userInfoName[0].innerHTML = Response.data.data.userInfo.name;
        userInfoName[1].innerHTML = Response.data.data.userInfo.name;
        createTime.innerHTML = Response.data.data.createTime;
        userInfoAvatarImg0.src = Response.data.data.userInfo.avatar;
        userInfoAvatarImg1.src = Response.data.data.userInfo.avatar;
        passageContent.innerHTML = Response.data.data.content;
        if (Response.data.data.coverUrl == null) {
            passageImg.style.display = 'none';
        } else {
            passageImg.style.display = 'block';
            coverUrl.src = Response.data.data.coverUrl;
        }

        userInfoJob.innerHTML = Response.data.data.userInfo.job;
        userInfoCompany.innerHTML = Response.data.data.userInfo.company;
        likeCount.innerHTML = Response.data.data.likeCount;
        commentCount.innerHTML = Response.data.data.commentCount;
    }

    // 清除缓存
    sessionStorage.removeItem('finalUrl');
})



















